package com.tangding.shiro.configurations;

import org.apache.shiro.mgt.RememberMeManager;
import org.apache.shiro.web.mgt.CookieRememberMeManager;
import org.apache.shiro.web.servlet.Cookie;
import org.apache.shiro.web.servlet.SimpleCookie;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.tangding.common.data.Constants;
import com.tangding.common.utils.Base64;

/**
 * @description 
 *
 * @author Ranger
 * @version 2017年11月8日_下午10:26:06
 *
 */
@Configuration
public class ShiroRememberMeConfiguration {
	
	@Bean(name="rememberMeManager")
	public RememberMeManager rememberMeManager(@Qualifier("rememberMeCookie") Cookie rememberMeCookie) {
		CookieRememberMeManager manager = new CookieRememberMeManager();
		manager.setCipherKey(Base64.decode("4AvVhmFLUs0KTA3Kprsdag=="));
		manager.setCookie(rememberMeCookie);
		return manager;
	}
    
    @Bean(name="rememberMeCookie")
    public Cookie rememberMeCookie() {
    	Cookie sc = new SimpleCookie("rememberMe");
    	sc.setMaxAge(Constants.LOGIN_COOKIE_EXPIRED);
    	sc.setPath("/");
    	sc.setHttpOnly(true);
    	return sc;
    }
}
